<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>svn获取不同版本文件的最高版本，列出文件与对应的版本号</title>
<style type="text/css">
* {
	margin: 0;
	padding: 0;
	font-size: 12px;
	line-height: 25px;
}

#loginBox {
	width: 300px;
	border: 1px solid #ccc;
	background: #FFF;
}

h1 {
	height: 35px;
	line-height: 35px;
	background: #e8e8e8;
	font-size: 14px;
	border-bottom: 1px solid #ccc;
	text-indent: 5px;
}

input.name,input.code {
	width: 150px;
	height: 25px;
	border: 1px solid #ccc;
	margin: 0 0 0 0px;
	padding: 0 0 0 20px;
}

input.verifyCode {
	height: 25px;
	width: 75px;
	border: 1px solid #ccc;
}


input.loginBtn,input.registerBtn {
	width: 54px;
	height: 21px;
	border: none;
	margin: 5px;
}

html,body {
	/*background: url("../images/background-top.png") no-repeat scroll 0 0 #318DAC;*/
	border: 0px solid #333333;
	color: #333333;
	font: 12px/150% Arial, Helvetica, sans-serif, '宋体';
	margin: 0;
	padding: 0;
	font-family: Arial, Tahoma, Verdana, sans-serif;
	font-size: 12px;
}


.header {
	height: 88px;
	margin-top: auto;
	padding: 0 10px;
	position: relative;
	background: 
		#318DAC;
}

#uploadFileDiv {
	height: 50px;
	overflow: hidden;
}

#fileQueue {
	width: 500px;
	padding: 10px;
	max-height: 220px;
	overflow: hidden;
}

.imgWrap {
	padding: 2px;
	border: 1px solid #ccc;
	float: left;
	margin-left: 10px;
	margin-top: 10px;
}

#progressBar {
	border: 1px solid #ccc;
	width: 500px;
	height: 20px;
	clear: both;
	margin-left: 10px;
	position: relative;
}

#progressInner {
	background: red;
	width: 0%;
	height: 20px;
}

#progressMsg {
	width: 100%;
	text-align: center;
	color: #000;
	font-weight: bold;
	position: absolute;
	left: 0;
	top: 0;
}

#left {
	color: red;
	padding: 0 5px;
	font-weight: bold;
	font-size: 14px;
}

.readonly {
	background: #eee;
	border: 1px solid #ccc;
	padding: 2px 5px;
}

.handler {
	width: 15px;
	height: 10px;
	border-right: solid 1px #888;
	border-bottom: solid 1px #888;
	float: right; right : 1px;
	bottom: 1px;
	cursor: nw-resize;
	right: 1px;
}
img{border:1px solid #ccc;}
textarea{overflow:auto;}
</style>
</head>
<body>
<?php
$content="";
$result = "";
if(!empty($_POST)){
	
	$content = trim($_POST['content']);
	$patterns = array(
		'/版本/',
		'/作者/',
		'/日期/',
		'/信息/',
	);
	$replace = array(
		'Revision',
		'Author',
		'Date',
		'Message',
	);


foreach($patterns as $k=> $p){

	$content = preg_replace($p,$replace[$k],$content);
}
	$content =  preg_replace('/Message:\s+/','Message:',$content);
	$result = $content;
	$result = preg_replace('/Author:.*/','',$result);
	$result = preg_replace('/Date:.*/','',$result);
	$result = preg_replace('/[a-zA-Z]+ : \//',': /',$result);
	
	$result = preg_replace('/\s+/',' ',$result);
	$result = preg_replace('/----/','
	----',$result);
	
	$result = preg_replace('/Message:.*/','',$result);
	$result = preg_replace('/----/',' ',$result);
		//print_r($result);exit;
	$result = preg_replace('/[^ a-zA-Z0-9\/:\.\-_]/','',$result);
	//print_r($result);exit;
	//$result = trim($result,'Revision:');
	
	$result = preg_replace('/^(Revision:)/','',$result);
	$result = explode('Revision:',$result);
	
	$all = array();
	try{
		
		foreach($result as $v){
			$arr = explode(':',$v);
			$banben = trim($arr[0]);
			$banben = intval($banben);
			if($banben==0){
				throw new Exception('某些文件未包含版本号'.$v);
			}
			unset($arr[0]);
			foreach($arr as $v1){
				$v1=trim($v1);
				if(!isset($all[$v1])||$all[$v1]<$banben){
					$all[$v1] = $banben;
				}
				
			}
		}
	
	}catch(Exception $e){
		echo $e->getMessage();
		exit;
	}
	$result = "";
	foreach($all as $k=>$v){
		if(!preg_match('/\./',$k)){
			continue;
		}
		$result.=$k." ".$v."\n";
	}
	$result = trim($result);
	//$result = $content;
	//print_r($all );
}
?>
	
	<div style="margin-top: 0; padding: 5px;">
		<h1>svn获取不同版本文件的最高版本，列出文件与对应的版本号[避免手写出现错误]</h1>
		<form method='post' style='padding:5px 0 0;'>		
		<textarea id="elm1" name="content" rows="8" cols="50" style="width: 50%;float:left;"><?php echo $content;?></textarea>
		<input type='submit' name='submit' class='verifyCode' value='提交' style='float:left;margin:0 5px;'/>
		<?php if($result){?>
		<textarea   rows="8" cols="50" style="width: 40%;clear:both;margin:0px 0;"><?php echo $result;?></textarea>
		<?php }?>
		</form>
		
		<div style="clear:both;">
		
		<img src="1.jpg"/><br/>
		<img src="3.jpg"/><br/>
		<img src="4.jpg"/>
		<span style="font-size:20px;font-weight:bold;">点击提交，获取结果</span>
		</div>
	</div>

</body>
</html>
